package com.zzyl.controller;


import com.aliyun.iot20180120.models.*;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;

import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/iot")
@Api(tags = "管理端 - 物联网iot相关接口")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;


    //1.1 从物联网平台同步产品列表
    @RequestMapping("/syncProductList")
    @ApiOperation(value = "从物联网平台同步产品列表")
    public ResponseResult syncProductList() {
        deviceService.syncProductList();
         return ResponseResult.success();
    }

    //1.2 查询所有产品列表
    @GetMapping("/allProduct")
    @ApiOperation(value = "查询所有产品列表")
    public ResponseResult<List<ProductVo>> allProduct() {
       List<ProductVo> productVoList = deviceService.allProduct();
       return ResponseResult.success(productVoList);
    }

    //新增设备
    @PostMapping("/RegisterDevice")
    @ApiOperation(value = "新增设备")
    public ResponseResult RegisterDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.add(deviceDto);
        return ResponseResult.success();
    }

    //分页查询
    @GetMapping("/pageQueryDevice")
    @ApiOperation(value = "分页查询")
    public ResponseResult pagequerydevice(DevicePageQueryDto devicePageQueryDto) {
       PageResponse<DeviceVo> pageResponse = deviceService.pagequerydevice(devicePageQueryDto);
        return ResponseResult.success(pageResponse);
    }

    //获取设备详情
    @PostMapping("/QueryDeviceDetail")
    @ApiOperation(value = "获取设备详情")
    public ResponseResult QueryDeviceDetail(@RequestBody QueryDeviceDetailRequest request) {
        DeviceVo deviceVo = deviceService.QueryDeviceDetail(request);
        return ResponseResult.success(deviceVo);
    }
    //1.7 查看指定产品的已发布物模型中的功能定义详情
    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request) {
        QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData data = deviceService.queryThingModelPublished(request);
        return ResponseResult.success(data);
    }


    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData data = deviceService.queryDevicePropertyStatus(request);
        return ResponseResult.success(data);
    }


}
